﻿using System.Xml.Serialization;

namespace CnSharp.SSMS.AddIn.Framework.AddinControls
{
    [XmlInclude(typeof (CommandMenu))]
    [XmlInclude(typeof (CommandButton))]
    [XmlInclude(typeof (ObjectContextMenu))]
    public class CommandControl
    {
        private int _position;

        public CommandControl()
        {
            CommandActionType = CommandActionType.menu;
            Position = 1;
        }

        [XmlAttribute("id")]
        public string Id { get; set; }

        [XmlAttribute("text")]
        public string Text { get; set; }

        [XmlAttribute("tooltip")]
        public string Tooltip { get; set; }

        [XmlAttribute("faceId")]
        public int FaceId { get; set; }

        /// <summary>
        /// 控件在父控件上的相对位置，相对于控件总数n而言，大于等于0则放在末尾n+1的位置，为负数则放在倒数第n-Position的位置
        /// </summary>
        [XmlAttribute("position")]
        public int Position
        {
            get { return _position; }
            set
            {
                if (value >= 0)
                    value = 1;
                _position = value;
            }
        }

        [XmlAttribute("picture")]
        public string Picture { get; set; }

        [XmlAttribute("class")]
        public string ClassName { get; set; }

        [XmlAttribute("type")]
        public CommandActionType CommandActionType { get; set; }

        [XmlAttribute("attachTo")]
        public string AttachTo { get; set; }

        //[XmlAttribute("hotKey")]
        //public string HotKey { get; set; }

        [XmlAttribute("beginGroup")]
        public bool BeginGroup { get; set; }

        public override string ToString()
        {
            return Text;
        }
    }
}